export interface IProduct {
    id: number
    title: string
    price: number
    inventory: number //库存
}

const _product: IProduct[] = [
    { id: 1, title: 'ipad', price: 5999, inventory: 1 },
    { id: 2, title: 'iphone', price: 4999, inventory: 10 },
    { id: 3, title: 'imarch', price: 14999, inventory: 5 },
    { id: 3, title: 'iwatch', price: 2999, inventory: 20 },
]

/**
 * 获取商品列表
 * @returns 
 */
export const getProduct = async () => {
    await wait(100);
    return _product
}

/**
 * 订单结算
 * @returns 
 */
export const buyProduct = async () => {
    await wait(100);
    return Math.random() > 0.5
}
async function wait(delay: number) {
    return new Promise((resolve) => {
        setTimeout(resolve, delay)
    })
}

